package sqlapi

import groovy.sql.GroovyRowResult
import groovy.sql.Sql


class HRDBSqlApiService {

    def dataSource


    List<GroovyRowResult> query(QueryParamsCommand queryParamsCommand) {
        def hrSql = new Sql(dataSource)
        try{
            if (queryParamsCommand.params) {
                if (queryParamsCommand.offset != null && queryParamsCommand.maxRows != null) {
                    return hrSql.rows(queryParamsCommand.sqlString, queryParamsCommand.params, queryParamsCommand.offset, queryParamsCommand.maxRows)
                } else
                    return hrSql.rows(queryParamsCommand.sqlString, queryParamsCommand.params)
            } else {
                if (queryParamsCommand.offset != null && queryParamsCommand.maxRows != null) {
                    return hrSql.rows(queryParamsCommand.sqlString, queryParamsCommand.params)
                } else
                    return hrSql.rows(queryParamsCommand.sqlString)
            }
        }finally {
            hrSql.close()
        }
    }



}
